package com.diors.test.main;

import java.nio.ByteOrder;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.diors.commons.thread.ThreadUncaughtExceptionHandler;
import com.diors.test.network.TestServer;




/**
 * 客户端模拟连接主函数
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-21
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
public class ClientMain 
{
	static final Logger log = Logger.getLogger(ClientMain.class);
	
	public static void main(String[] args) 
	{
		/*DiorsClient client = new DiorsClient(dispatcher, "192.168.0.107", 8080);
		client.open();*/
		PropertyConfigurator.configure("./log/log4j.properties");
		
		log.info("<========================= 服务器开始启动 =========================>");
		
		//设置线程由于未捕获到异常而突然终止时调用的默认处理程序。
		Thread.setDefaultUncaughtExceptionHandler(new ThreadUncaughtExceptionHandler());
		
		TestServer server = TestServer.connect("192.168.0.107", 8080);
		
		ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 256);
		/**往流写入模块，命令号**/
		/*buffer.writeShort(1002);
		buffer.writeShort(1001);
		buffer.writeShort(3);*/
		
		buffer.writeShort(1);
		buffer.writeShort(200);
		buffer.writeLong(10080);
		
		//buffer.writeShort(moduleId);
		//buffer.writeShort(opcode);
		//buffer.writeShort(result);
		/**解析命令**/
		ChannelBuffer channelBuffer = null;
		/**写入长度**/
		channelBuffer = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, buffer.writerIndex() + 4);
		channelBuffer.writeInt(buffer.writerIndex());
		channelBuffer.writeBytes(buffer);
		
		server.write(channelBuffer);
		
	}

}
